home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / wtj208.zip / ZEMPEL / SOURCE / UT32 / UT32.C < prev    next >
C/C++ Source or Header  |  1993-05-08  |  3KB  |  158 lines

  1. /*
  2.     ut32.c      the main source code for the 32 bit UT DLL
  3.         ut32.dll is loaded by a 32 bit application,
  4.         sets up the UT for use by both sides
  5.         needs w32sut.h and w32sut32.lib from the March 1993 NT SDK
  6. */
  7.  
  8. #define W32SUT_32
  9. #define CALC_SRV_ADDTWO       0   //indicate type of 32 bit function
  10. #define CALC_SRV_SUBTWO       1
  11. #define CALC_SRV_MULTTWO      2
  12. #define CALC_SRV_DIVTWO       3
  13. #define SUM_ARRAY             4
  14.  
  15. #include <windows.h>
  16. #include "w32sut.h"
  17. #include "ut32.h"
  18.  
  19. UT32PROC  pfnUTProc=NULL;
  20.  
  21. int       cProcessesAttached = 0;
  22. long      a, b, ret, ArraySize, ArraySum, sum, SizeofArray, Index; 
  23. long      *SumAddress;
  24.  
  25. BOOL 
  26. DllInit(HANDLE hInst, DWORD fdwReason, LPVOID lpReserved)
  27. {
  28.     if ( fdwReason == DLL_PROCESS_ATTACH ) {
  29.      if ( cProcessesAttached++ ) {
  30.      return(TRUE);
  31.     }
  32. /*  UTRegister sets up the UT for both directions
  33.     It is the key function in ut32.dll 
  34.     to use (16->32) thunk, both valid (32->16) and (16->32) thunks must be set up */    
  35.  
  36.     return UTRegister( hInst,        // ut32.dll module handle
  37.                "UT16.DLL",   // name of 16 bit thunk dll
  38.                "CBInit",     // name of 16 bit exported initialization function, receives 16->32 thunk address in ut16.dll
  39.                "UTProc",     // name of 16 bit (32->16) thunk function exported from ut16.DLL
  40.                &pfnUTProc,   // global variable to receive (32->16) thunk address
  41.                &CB32,        // address of (16->32) thunk function in ut32.dll
  42.                NULL          // no shared memory set up from 32 bit side
  43.              );
  44.     } 
  45.     else if ( fdwReason == DLL_PROCESS_DETACH ) {
  46.        if ( --cProcessesAttached == 0 ) {
  47.        UTUnRegister( hInst );
  48.        }
  49.     }
  50. }
  51.  
  52. /*      (32 -> 16) thunk functions */
  53.  
  54. long AddTwo(LPDWORD *Arrayn)
  55. {
  56.     ret= (long)(* pfnUTProc)(Arrayn,CALC_SRV_ADDTWO, NULL);
  57.     return(ret);
  58. }
  59.  
  60. long SubTwo(LPDWORD *Arrayn)
  61. {
  62.     ret= (long) (* pfnUTProc)(Arrayn,CALC_SRV_SUBTWO, NULL);
  63.     return(ret);
  64. }
  65.  
  66. long MultTwo(LPDWORD *Arrayn)
  67. {
  68.     ret= (long) (* pfnUTProc)(Arrayn,CALC_SRV_MULTTWO, NULL);
  69.     return(ret);
  70. }
  71.  
  72. long DivTwo(LPDWORD *Arrayn)
  73. {
  74.     ret= (long) (* pfnUTProc)(Arrayn,CALC_SRV_DIVTWO, NULL);
  75.     return(ret);
  76. }
  77.  
  78. /*      32 bit functions called from 32 bit side */
  79.  
  80. long AddTwoDLL32(LPDWORD *Arrayn)
  81. {       
  82.     a=*Arrayn;
  83.     b=*(++Arrayn);
  84.     ret=a+b;
  85.     return(ret);
  86. }
  87.  
  88. long SubTwoDLL32(LPDWORD *Arrayn)
  89. {
  90.     a=*Arrayn;
  91.     b=*(++Arrayn);
  92.     ret=a-b;
  93.     return(ret);
  94. }
  95.  
  96. long MultTwoDLL32(LPDWORD *Arrayn)
  97. {
  98.     a=*Arrayn;
  99.     b=*(++Arrayn);
  100.     ret=a*b;
  101.     return(ret);
  102. }
  103.  
  104. long DivTwoDLL32(LPDWORD *Arrayn)
  105. {
  106.     a=*Arrayn;
  107.     b=*(++Arrayn);
  108.     ret=a/b;
  109.     return(ret);
  110.  
  111. }
  112.  
  113. /*      (16->32) thunk function 
  114.     arguments must be distributed due to fixed UT parameters */
  115.  
  116. long WINAPI CB32(LPDWORD *Arrayn, DWORD dwFunc)
  117. {    
  118.     switch (dwFunc) {
  119.     case CALC_SRV_ADDTWO:
  120.         a=*Arrayn;
  121.         b=*(++Arrayn);
  122.         *(++Arrayn)=a+b;
  123.         return(1l);
  124.  
  125.     case CALC_SRV_SUBTWO:
  126.         a=*Arrayn;
  127.         b=*(++Arrayn);
  128.         *(++Arrayn)=a-b;
  129.         return(1l);
  130.     
  131.     case CALC_SRV_MULTTWO:
  132.         a=*Arrayn;
  133.         b=*(++Arrayn);
  134.         *(++Arrayn)=a*b;
  135.         return(1l);
  136.     
  137.     case CALC_SRV_DIVTWO:
  138.         a=*Arrayn;
  139.         b=*(++Arrayn);
  140.         *(++Arrayn)=a/b;
  141.         return(1l);
  142.  
  143.     case SUM_ARRAY:
  144.         sum=0;
  145.         SizeofArray=*Arrayn;
  146.         Arrayn++;
  147.         SumAddress=Arrayn;
  148.         for (Index=0;Index<(SizeofArray); Index++)
  149.             {  Arrayn++;
  150.                b=*Arrayn;
  151.                sum += b; }
  152.         *SumAddress=sum;
  153.         return(1l);
  154.     };   
  155. }
  156.  
  157.  
  158.